/**
 * 
 */
package br.coppe.coimbra.document.doc.extraction;

import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import br.coppe.coimbra.readability.category.Cat;

/**
 * @author phillipe
 *
 */
public class Dir {

	List<String[]> catFileList;
	
	public  List<String[]>  categorizeDir(String pathname) throws FileNotFoundException, IOException {
		
		File dir = new File(pathname);
	
		FileFilter filter = new FileFilter() {  
			
		    public boolean accept(File file) {
		    	
		    	return file.getName().matches("^[^.].*[^~]$");
		    }  
		};  
		
		File[] fileList = dir.listFiles(filter);
		
		Cat cat = new Cat();
		this.catFileList = new ArrayList<String[]>();
		
		for (File f:  fileList)
			catFileList.add(cat.categorize(f));
		
		showList();
		
		return this.catFileList;
	}
	
	private void showList() {
		
		for (String[] l: this.catFileList) {
			System.out.println(l[0] +" " + l[1]  +" " + l[2]  +" " +  l[3] +" " +  l[4]);
		}
	}

	public  void save(String pathname) throws IOException {
		
		FileWriter fw = new FileWriter(new File(pathname + "/classificacao.txt"));
		for (String[] list: catFileList) {
			String lista = "Nome do arquivo: " + list[0] + "\n" +
								"FRE: " + list[1] + "\tCategoria Literária: " + list[3].split(";")[4] + "\n" +
								"FK: " + list[2] + "\tCategoria Literária: " + list[4].split(";")[2] + "\n" 	;
			fw.write(lista);
			fw.write("\n");
		}
		fw.close();
		
	}
	
}
